package cn.doctor.assistant.pad.api;

import android.app.Activity;

import com.android.volley.RequestQueue;
import com.android.volley.toolbox.Volley;

import java.util.HashMap;

import cn.doctor.assistant.pad.MyApplication;
import cn.doctor.assistant.pad.api.bean.AssRequest;
import cn.doctor.assistant.pad.base.BaseNetActivity;

/**
 * Created by jiaolf on 2016/3/21.
 * 接口
 */
public class AssistAPI {

    public static final boolean isDebug = true;

    public static String URL_DOMAIN;

    public static final String URL_DOMAIN_RELEASE  = "http://www.doctor-assistant.cn/";

    public static final String URL_DOMAIN_DEBUG = "http://192.168.0.122:8080/";

    static {
        URL_DOMAIN = (isDebug ? URL_DOMAIN_DEBUG : URL_DOMAIN_RELEASE) + "platform/mobile/http/api.do";
    }

    public static String sessionID;

    /****** 状态码  ********/
    public static String STATUS_CODE_SUCCESS = "1";
    public static String STATUS_CODE_FAIL = "0";

    /**
     * 构建请求（这里没有用这种方式）
     * @param method 请求方法
     * @param keyValue 请求参数
     * @return
     */
    public static AssRequest buildRequest(String method, String... keyValue){
        AssRequest assRequest = new AssRequest();

        HashMap<String, String> paramsMap = new HashMap<>();
        for (int i = 0; i < keyValue.length; i++) {
            String key = keyValue[i];
            String value = keyValue[++i];
            paramsMap.put(key, value);
        }
        assRequest.setParams(paramsMap);

        assRequest.setMethod(method);

        return assRequest;
    }

    public static RequestQueue getRequestQueue() {
        Activity activity = MyApplication.getInstance().getCurrentActivity();
        if (activity instanceof BaseNetActivity)
            return ((BaseNetActivity) activity).getRequestQueue();
        return Volley.newRequestQueue(activity);
    }
}
